package org.dandsoft.blackbox.mapreduce.client.task;

import java.util.*;

/**
 * @author Vilyuzhanin Denis (Fin)
 */
public class Task {

    private Map<String, Action> actions = new Hashtable<String, Action>();

    public void addAction(String name, ActionType type, ActionInfo actionObject) {
        Action action = new Action();
        action.setName(name);
        action.setType(type);
        action.setInfo(actionObject);
        actions.put(action.getName(), action);
    }

    public ActionInfo getActionInfo(String name) {
        return actions.get(name).getInfo();
    }

    public Set<String> getActions() {
        return actions.keySet();
    }

    public Set<String> getDependencies(String action) {
        return actions.get(action).getDependecies();
    }

    public ActionType getActionType(String name) {
        return actions.get(name).getType();
    }

    public void addDependency(String actionName, String dependencyActionName) {
        Action action = actions.get(actionName);
        Action dependencyAction = actions.get(dependencyActionName);
        if (dependencyAction != null) {
            action.getDependecies().add(dependencyActionName);
        }
    }

    class Action {

        private ActionType type;
        private String name;
        private Set<String> dependecies = new HashSet<String>();
        private ActionInfo info;

        public ActionInfo getInfo() {
            return info;
        }

        public void setInfo(ActionInfo info) {
            this.info = info;
        }

        public Set<String> getDependecies() {
            return dependecies;
        }

        public void setDependecies(Set<String> dependecies) {
            this.dependecies = dependecies;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }


        public ActionType getType() {
            return type;
        }

        public void setType(ActionType type) {
            this.type = type;
        }
    }

}
